#include <iostream>

using namespace std;
//分别利用普通写法和多态技术，设计实现两个操作数进行运算的计算器类
//多态的优点：
//1、代码组织结构清晰
//2、可读性强
//3、利于前期和后期的扩展以及维护


//多态写法
class AbstractCalculator{
public:
    int num1;
    int num2;
    virtual int getResult(){
        return 0;
    }
};
class Add:public AbstractCalculator{
public:
    int getResult(){
        return num1+num2;
    }
};
class Sub:public AbstractCalculator{
public:
    int getResult(){
        return num1-num2;
    }
};
class Mul:public AbstractCalculator{
public:
    int getResult(){
        return num1*num2;
    }
};
void test1(){
    AbstractCalculator *ac=new Add;
    ac->num1=10;
    ac->num2=10;
    cout<<ac->num1<<"+"<<ac->num2<<"="<<ac->getResult()<<endl;
    delete ac;

    ac=new Sub;
    ac->num1=10;
    ac->num2=10;
    cout<<ac->num1<<"-"<<ac->num2<<"="<<ac->getResult()<<endl;
    delete ac;

    ac=new Mul;
    ac->num1=10;
    ac->num2=10;
    cout<<ac->num1<<"*"<<ac->num2<<"="<<ac->getResult()<<endl;
    delete ac;
}
int main() {
    test1();
    return 0;
}